/*
 * 文件名：PushParkLot.java	 
 * 时     间：下午7:11:21
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.manager.thread;

import com.local.dao.mapers.CarParkInMapper;
import com.local.dao.mapers.CarParkOutMapper;
import com.local.entity.vo.CarParkInOverVo;
import com.local.model.CarParkInExample;
import com.local.model.CarParkOut;
import com.qianhai.common.utils.Log4jUtil;
import com.qianhai.common.utils.Tools;

/**
 * 类描述:推送车位信息,车位总数减去在场车辆
 * 
 * @ClassName: PushParkLot
 * @author Administrator
 * @date 2015年9月29日 下午7:11:21
 */
public class CarParkInThread implements Runnable
{
	private static Log4jUtil log = Log4jUtil.getLog4j(CarParkInThread.class);
	
	private CarParkInOverVo cv;
	
	private CarParkInMapper carInMapper;
	
	private CarParkOutMapper carOutMapper;
	
	
	public CarParkInThread(CarParkInOverVo cv,CarParkInMapper carInMapper,CarParkOutMapper carOutMapper)
	{
		super();
		this.cv = cv;
		this.carInMapper = carInMapper;
		this.carOutMapper = carOutMapper;
	}



	@Override
	public void run()
	{
		
		try
		{
			if(!Tools.isEmpty(cv)&&!Tools.isEmpty(cv.getCarparkIn())){
				carInMapper.insertSelective(cv.getCarparkIn());
			}
			// 删除多余已入场多余数据
			if (cv.getCarparkIn().getStatus() == 1
					&& !Tools.isEmpty(cv.getCarparkIn().getUuid())
					&& !cv.getCarparkIn().getCarNo().equals("")
					&& !cv.getCarparkIn().getCarNo().equalsIgnoreCase("无效车牌"))
			{
				CarParkInExample inEx = new CarParkInExample();
				inEx.or().andUuidNotEqualTo(cv.getCarparkIn().getUuid())
						.andStatusEqualTo(1)
						.andCarNoEqualTo(cv.getCarparkIn().getCarNo());
				carInMapper.deleteByCondition(inEx);
			}
			
			
			// 2015-12-15 如果重复车牌已经在出场纪录下,则更新出场纪录的进场数据
			CarParkOut carOut = carOutMapper.selectCarNo(cv.getCarparkIn().getCarNo());
			if (!Tools.isEmpty(carOut))
			{
				carOut.setCarInUuid(cv.getCarparkIn().getUuid());
				carOutMapper.updateByPrimaryKey(carOut);
			}
		} catch (Throwable e)
		{
			log.error("", e);
		}
	}
}
